import 'package:get/get.dart';
import 'package:pornhub_app/http/http_service.dart';
import 'package:pornhub_app/model/sys_partner_cell_model/sys_partner_cell_model.dart';

class AppRecommendPageController extends GetxController {
  ///推荐
  RxList<SysPartnerCellModel> recommends = <SysPartnerCellModel>[].obs;

  ///热门
  RxList<SysPartnerCellModel> populars = <SysPartnerCellModel>[].obs;

  @override
  void onInit() {
    super.onInit();
    initHttpData();
  }

  initHttpData() async {
    fetchPartnerList(1).then((result) {
      recommends.value = result;
    });
    fetchPartnerList(0).then((result) {
      populars.value = result;
    });
  }

  Future<List<SysPartnerCellModel>> fetchPartnerList(int labelType) async {
    try {
      List<SysPartnerCellModel> result = await httpInstance.get(
          url: "sys/partner/list",
          complete: SysPartnerCellModel.fromJson,
          queryMap: {
            "labelType": labelType,
          });
      return result;
    } catch (e) {
      return [];
    }
  }
}
